package com.zlyx.easy.log.model;

import com.zlyx.easy.core.event.LogEvent;
import com.zlyx.easy.core.tool.EasyBuffer;
import com.zlyx.easy.core.tool.Ops;
import com.zlyx.easy.core.utils.DateUtils;

public class LogModel {

	private String type;

	private String className;

	private String simpleName;

	private String msg;

	private String time;

	private String desc;

	public LogModel(LogEvent event) {
		if (event.getSource() != null) {
			this.className = ((Class<?>) event.getSource()).getName();
			this.simpleName = ((Class<?>) event.getSource()).getSimpleName();
			this.type = event.getType();
			this.msg = "" + event.getMsg();
			this.time = DateUtils.getNowMs();
		} else {
			this.desc = "" + event.getMsg();
		}
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getSimpleName() {
		return simpleName;
	}

	public void setSimpleName(String simpleName) {
		this.simpleName = simpleName;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	@Override
	public String toString() {
		if (Ops.isNotEmpty(desc)) {
			return desc;
		}
		return EasyBuffer.newBuffer("<span class='time'>", time, "</span>  ")
				.append("<span class='", type, "'>【", type, "】</span>  ")
				.append("<span class='classname'>", className, "</span>   : ")
				.append("<span class='", type, "  msg '>", msg, "</span>").toString().replace("\n", "<br>");
	}
}